package com.shanzmoo.core.config.pay;

import com.shanzmoo.base.constant.e.PayTypeEnum;
import com.shanzmoo.base.exception.PayException;
import com.shanzmoo.core.service.ICommonPayService;
import com.shanzmoo.core.service.impl.AliCommonPayServiceImpl;
import com.shanzmoo.core.service.impl.WxCommonPayServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *  支付服务配置类
 * @author Gzhao 2021/1/2
 */
@Configuration
public class PayServiceConfig {
    /**
     * 回调地址
     */
    @Value("${trade.pay.wxPayCallBack}")
    private String wxNotifyUrl;

    @Bean("aliCommonPayService")
    public ICommonPayService getAliCommonPayService(){
        return new AliCommonPayServiceImpl();
    }

    @Bean("wxCommonPayService")
    public ICommonPayService getWxCommonPayService(){
        return new WxCommonPayServiceImpl(wxNotifyUrl);
    }

    /**
     * 根据支付方式获取支付实现类
     * @param payType
     * @return
     */
    public ICommonPayService getPayService(PayTypeEnum payType) {
        switch (payType) {
            case Ali:
                return getAliCommonPayService();
            case Wx:
                return getWxCommonPayService();
            default:
                throw new PayException("支付方式不存在");
        }
    }
}
